﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MES数据展示
{
    internal class UIBarOption返回Option
    {
        public UIBarOption Start(DataTable t,params string[] bar)
        {
            string bar1 = bar[0];
            string bar2 = bar[1];
            string bar3 = bar[2];
            UIBarOption option = new UIBarOption();
            option.Title = new UITitle();
            string[] res = t.TableName.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            option.Title.Text = res[0];
            option.Title.SubText = $"{res[1]} {res[2]}";

            option.Legend = new UILegend();
            option.Legend.Orient = UIOrient.Horizontal;//图例水平布局
            option.Legend.Top = UITopAlignment.Top;
            option.Legend.Left = UILeftAlignment.Left;
            option.Legend.Colors.Add(Color.Orange);
            option.Legend.AddData(bar1);
            option.Legend.Colors.Add(Color.ForestGreen);
            option.Legend.AddData(bar2);
            option.Legend.Colors.Add(Color.BlueViolet);
            option.Legend.AddData(bar3);


            UIBarSeries series = new UIBarSeries();//设置系列
            series.Name = bar1;
            foreach (DataRow row in t.Rows)
            {
                series.Colors.Add(Color.Orange);
                series.AddData((float)row[bar1]);
            }
            option.Series.Add(series);

            series = new UIBarSeries();
            series.Name = bar2;
            foreach (DataRow row in t.Rows)
            {
                series.Colors.Add(Color.ForestGreen);
                series.AddData((float)row[bar2]);
            }
            option.Series.Add(series);

            series = new UIBarSeries();
            series.Name = bar3;
            foreach (DataRow row in t.Rows)
            {
                series.Colors.Add(Color.BlueViolet);
                series.AddData((float)row[bar3]);
            }
            option.Series.Add(series);



            foreach (DataRow row in t.Rows)
            {
                option.XAxis.Data.Add(row["制程名称"].ToString());
            }


            //辅助TIP
            option.ToolTip.Visible = true;
            option.ShowValue = true;

            //设置坐标内容
           // option.YAxis.Name = 纵坐标名称;
            option.YAxis.SetMaxValue(3500);
            //option.XAxis.Name = 横坐标名称;
            return option;
        }
    }
}
